package com.cicadamob.contact.api.Utils;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources.NotFoundException;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Environment;
import android.provider.ContactsContract;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.format.DateFormat;
import android.text.style.ForegroundColorSpan;
import android.util.Base64;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 提供操作字符串及日期时间转化的通用方法
 * 
 * @author 张锋
 * 
 */
public class StringUtil {
	/**
	 * 常用人
	 */
	public static final int CONTACT_PERSON = 1;
	/**
	 * 常用组
	 */
	public static final int CONTACT_GROUP = 2;
	/**
	 * 群组人
	 */
	public static final int GROUP_PERSON = 3;
	/**
	 * 短信
	 */
	public static final int CONTACT_MESSAGE = 4;

	public static StringBuffer getBuffer() {
		return new StringBuffer();
	}

	public static String subString(String str, int num) {
		if (StringUtil.isEmpty(str))
			return null;
		int len = str.length();

		if (len > num)
			return str.substring(0, num);
		return str;
	}

	public static boolean isPhoneNumberValid(String phoneNumber) {
		boolean isValid = false;
		String expression = "^//(?(//d{3})//)?[- ]?(//d{3})[- ]?(//d{5})$";
		String expression2 = "^//(?(//d{3})//)?[- ]?(//d{4})[- ]?(//d{4})$";
		CharSequence inputStr = phoneNumber;
		Pattern pattern = Pattern.compile(expression);
		Matcher matcher = pattern.matcher(inputStr);
		Pattern pattern2 = Pattern.compile(expression2);
		Matcher matcher2 = pattern2.matcher(inputStr);
		if (matcher.matches() || matcher2.matches()) {
			isValid = true;
		}
		return isValid;

	}

	/**
	 * 判断IP地址是否有效
	 * 
	 * @param IPAddress
	 * @return
	 */
	public static boolean isIPAddressValid(String IPAddress) {
		boolean isValid = false;
		Pattern pattern = Pattern
				.compile("\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b");
		Matcher matcher = pattern.matcher(IPAddress);
		if (matcher.matches()) {
			isValid = true;
		}
		return isValid;

	}

	/**
	 * 判断字符串的编码
	 * 
	 * @param str
	 * @return
	 */
	public static String getEncoding(String str) {
		String encode = "GB2312";
		try {
			if (str.equals(new String(str.getBytes(encode), encode))) {
				return encode;
			}
		} catch (Exception exception) {
		}
		encode = "ISO-8859-1";
		try {
			if (str.equals(new String(str.getBytes(encode), encode))) {
				return encode;
			}
		} catch (Exception exception1) {
		}
		encode = "UTF-8";
		try {
			if (str.equals(new String(str.getBytes(encode), encode))) {
				return encode;
			}
		} catch (Exception exception2) {
		}
		encode = "GBK";
		try {
			if (str.equals(new String(str.getBytes(encode), encode))) {
				return encode;
			}
		} catch (Exception exception3) {
		}
		return "";
	}

	public static String arrayToJson(String key, ArrayList<Integer> array) {
		JSONArray jsonArray = new JSONArray();
		try {
			if (array != null) {
				for (Integer obj : array) {
					JSONObject object = new JSONObject();
					try {
						object.put(key, obj);
					} catch (JSONException e) {
						e.printStackTrace();
					}
					jsonArray.put(object);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonArray.toString();
	}

	public static String getRandChar(String source) {
		if (StringUtil.isEmpty(source))
			return "";
		int length = source.length();
		Random rand = new Random();
		char[] chars = source.toCharArray();
		int index = rand.nextInt(length);
		return chars[index] + "";
	}

	/**
	 * 两日期相减
	 * 
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public static long diffDate(int num) {
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());

		c.add(Calendar.DAY_OF_MONTH, (0 - num));
		return c.getTime().getTime();
	}

	public static int toInt(String num) {
		try {
			return Integer.parseInt(num);
		} catch (Exception e) {
			return 0;
		}
	}

	public static long toLong(String num) {
		try {
			return Long.parseLong(num);
		} catch (Exception e) {
			return 0;
		}
	}

	public static boolean toBoolean(String num) {
		if (isEmpty(num))
			return false;
		if (num.equals("true"))
			return true;
		return false;
	}

	public static String getStrDate(String longDate) {
		if (isEmpty(longDate))
			return "";
		long time = Long.parseLong(longDate);
		Date date = new Date(time);
		return getStrDate(date, "MM-dd HH:mm");
	}

	public static String getStrDate(String longDate, String format) {
		return isEmpty(longDate) ? "" : getStrDate(
				new Date(Long.parseLong(longDate)), format);
	}

	public static String getStrDate(long time, String format) {
		Date date = new Date(time);
		return getStrDate(date, format);
	}

	public static Date getDate(String longDate) {
		if (isEmpty(longDate))
			return null;
		long time = Long.parseLong(longDate);
		return new Date(time);
	}

	public static String[] getData(String str) {
		String empty[] = { "", "" };
		if (isEmpty(str))
			return empty;
		try {
			int start = str.indexOf(":");
			if (start > 0 && start < str.length()) {
				empty[0] = str.substring(0, start);
				empty[1] = str.substring(start + 1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return empty;
	}

	public static final String ENCODING = "utf-8";

	private StringUtil() {
	}

	public static String getStrDate() {
		SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd");
		return dd.format(new Date());
	}

	public static String getStrDate(Date date) {
		SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd");
		return dd.format(date);
	}

	public static String getStrDate(Date date, String formate) {
		return new SimpleDateFormat(formate).format(date);
	}

	public static String encode(String data) {
		try {
			return URLEncoder.encode(data, ENCODING);
		} catch (Exception e) {
			return "";
		}
	}

	public static String decode(String data) {
		try {
			return URLDecoder.decode(data, ENCODING);
		} catch (UnsupportedEncodingException e) {
			return "";
		}
	}

	// 随机数字产生
	public static String getRandomStr(int num) {
		StringBuffer temp = new StringBuffer();
		Random rand = new Random();
		for (int i = 0; i < num; i++) {
			temp.append(rand.nextInt(10));
		}
		return temp.toString();
	}

	/**
	 * 判断指定的字符串是否为null或空字符串
	 * 
	 * @param str
	 * @return
	 */
	public static final boolean isNullOrEmpty(String str) {
		if ((str == null) || "".equals(str)) {
			return true;
		}

		return false;
	}

	/**
	 * 判断指定的字符串是否为null、空字符串或空格字符串
	 * 
	 * @param str
	 * @return
	 */
	public static final boolean isNullOrTrimEmpty(String str) {
		if ((str == null) || "".equals(str.trim())) {
			return true;
		}

		return false;
	}

	/**
	 * 判断指定的字符串不为null，空字符串
	 * 
	 * @param str
	 * @return
	 */
	public static final boolean isNotNullOrEmpty(String str) {
		if ((str == null) || "".equals(str) || "null".equals(str)) {
			return false;
		}

		return true;
	}

	public static String toStrNum(int num, int n) {
		String pat = "";
		for (int i = 0; i < n; i++)
			pat = pat + "0";
		java.text.DecimalFormat format = new java.text.DecimalFormat(pat);
		return format.format(num);
	}

	public static String filterChar(String str, String replace) {
		if (isEmpty(str))
			return "";
		str = str.replace("\\", replace);
		str = str.replace("\"", replace);
		str = str.replace("\'", replace);
		String reg = "@'\"？`~!@#$%^&*()_+={[}]|\\:;<>.?/-Aa%！￥……（）、：；“”’‘《》，。？－";
		for (int i = 0; i < reg.length(); i++) {
			str = str.replace(reg.substring(i, i + 1), replace);
		}

		return str;
	}

	public static String urlDecode(String str) {
		if (isEmpty(str))
			return "";
		return str.replace("&amp;", "&");
	}

	public static boolean isMobile(String str) {
		if (str == null || str.equals("") || str.trim().equals(""))
			return false;

		if (str.length() == 11 && isNum(str)) {
			if (str.startsWith("1"))
				return true;
		}

		return false;
	}

	public static boolean isNum(String str) {
		for (int i = str.length(); --i >= 0;)
			if (!Character.isDigit(str.charAt(i)))
				return false;
		return true;
	}

	/**
	 * 快速判断是否是数字
	 * 
	 * @param str
	 * @return
	 */
	public static boolean fIsNum(String str) {
		for (int i = str.length(); --i >= 0;) {
			int is = str.charAt(i);
			// ascii
			if (is < 48 || is > 57)
				return false;
		}
		return true;
	}

	public static boolean isEmpty(String str) {
		if (str == null || str == "" || str.trim().equals("")
				|| str.trim().equalsIgnoreCase("null")
				|| str.trim().length() == 0)
			return true;
		else
			return false;
	}

	public static boolean isNotEmptyAndNum(String str) {
		if (isEmpty(str)) {
			return false;
		}
		for (int i = str.length(); --i >= 0;)
			if (!Character.isDigit(str.charAt(i)))
				return false;
		return true;
	}

	public static int getPixWidth(String str, Paint paint) {
		Rect rect = new Rect();

		// 返回包围整个字符串的最小的一个Rect区域
		paint.getTextBounds(str, 0, str.length(), rect);

		return rect.width();
	}

	/*
	 * 显示游戏描述函数 可以 收集为自动换行函数 showrect -- 有效显示区域 by -- 开始显示的y坐标 x坐标根据showrect给出
	 * 返回字符串总的行数
	 */
	public static int drawStringInRect(Canvas canvas, String text,
			Rect showrect, int by, Paint paint) {
		int x, y;
		int count = 1;

		x = showrect.left + (int) paint.getTextSize();
		y = by;
		float pos[] = new float[text.length() * 2];
		float widths[] = new float[text.length()];
		paint.getTextWidths(text, widths);
		for (int i = 0; i < pos.length; i += 2) {
			pos[i] = x;
			pos[i + 1] = y;

			if (i / 2 + 1 < widths.length) {
				if (x + widths[i / 2] + widths[i / 2 + 1] <= showrect.right) {
					x += widths[i / 2];
				} else {
					x = showrect.left;
					y += paint.getTextSize() + 5;
					count++;
				}
			} else {
				if (x + widths[i / 2] <= showrect.right) {
					x += widths[i / 2];
				} else {
					x = showrect.left;
					y += paint.getTextSize() + 5;
					count++;
				}
			}

		}

		canvas.drawPosText(text, pos, paint);

		return count;
	}

	public static void writeUnicode(final DataOutputStream out,
			final String value) {
		try {
			final String unicode = gbEncoding(value);
			final byte[] data = unicode.getBytes();
			final int dataLength = data.length;
			out.writeInt(dataLength); // 先写出字符串的长度
			out.write(data, 0, dataLength); // 然后写出转化后的字符串
		} catch (IOException e) {

		}
	}

	public static String gbEncoding(final String gbString) {
		char[] utfBytes = gbString.toCharArray();
		String unicodeBytes = "";
		for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
			String hexB = Integer.toHexString(utfBytes[byteIndex]);
			if (hexB.length() <= 2) {
				hexB = "00" + hexB;
			}
			unicodeBytes = unicodeBytes + "\\\\u" + hexB;
		}
		return unicodeBytes;
	}

	public static String gbEncoding(final char utfByte) {
		String hexB = Integer.toHexString(utfByte);
		if (hexB.length() <= 2) {
			hexB = "00" + hexB;
		}
		return hexB;
	}

	/** */
	/*****************************************************
	 * 功能介绍:将unicode字符串转为汉字 输入参数:源unicode字符串 输出参数:转换后的字符串
	 *****************************************************/
	private String decodeUnicode(final String dataStr) {
		int start = 0;
		int end = 0;
		final StringBuffer buffer = new StringBuffer();
		while (start > -1) {
			end = dataStr.indexOf("\\\\u", start + 2);
			String charStr = "";
			if (end == -1) {
				charStr = dataStr.substring(start + 2, dataStr.length());
			} else {
				charStr = dataStr.substring(start + 2, end);
			}
			char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
			buffer.append(new Character(letter).toString());
			start = end;
		}
		return buffer.toString();
	}

	public static String computeTime(long time) {
		String _time = "";
		if (time / 3600 > 1) {

		} else {
			if (time < 60) {
				if (time < 10) {
					_time = "00:0" + time;
				} else {
					_time = "00:" + time;
				}
			} else {
				if (time % 60 == 0) {
					if (time / 60 >= 10) {
						_time = time / 60 + ":" + "00";
					} else {
						_time = "0" + time / 60 + ":" + "00";
					}
				} else {
					if (time / 60 >= 10) {
						if (time % 60 >= 10) {
							_time = time / 60 + ":" + time % 60;
						} else {
							_time = time / 60 + ":0" + time % 60;
						}
					} else {
						if (time % 60 >= 10) {
							_time = "0" + time / 60 + ":" + time % 60;
						} else {
							_time = "0" + time / 60 + ":0" + time % 60;
						}
					}
				}
			}
		}
		return _time;
	}

	/**
	 * 处理时间 秒、分钟、小时、天
	 * 
	 * @param date
	 *            消息时间
	 */
	public static String dateProcess1(String date) {

		String formatStr = "yyyyMMdd-HH:mm:ss";

		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		Date sendDate = null;
		try {
//			sendDate = format.parse(date);
			sendDate=new Date(Long.parseLong(date));
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 当前时间
		Date curDate = new Date(System.currentTimeMillis());

		// 分钟间隔
		int minDiff = (int) ((curDate.getTime() - sendDate.getTime()) / 1000);
		String dateStr = "";

		// 60秒内
		if (minDiff < 60) {
			return minDiff + "秒前";
		}

		// 30分钟内
		if (minDiff < 3600 / 2) {
			return minDiff / 60 + "分钟前";
		}

		// N天内
		switch ((int) ((curDate.getTime() - sendDate.getTime()) / 1000 / 3600 / 24)) {
		case 0:
			formatStr = "HH:mm";
			format.applyPattern(formatStr);
			dateStr = curDate.getDate() != sendDate.getDate() ? "昨天 "
					+ format.format(sendDate) : format.format(sendDate);
			break;
		case 1:
			if (curDate.getDate() - sendDate.getDate() < 2) {
				formatStr = "HH:mm";
				format.applyPattern(formatStr);
				dateStr = "昨天 " + format.format(sendDate);
			} else {
				formatStr = "MM-dd";
				format.applyPattern(formatStr);
				dateStr = format.format(sendDate);
			}
			break;
		default:
			formatStr = "MM-dd";
			format.applyPattern(formatStr);
			dateStr = format.format(sendDate);
			break;
		}
		return dateStr;
	}

	public static String dateProcess(long d) {
		String formatStr = "yyyyMMdd-HH:mm:ss";
		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		String currDate = format.format(new Date(d));
		return dateProcess(currDate);
	}

	

	public static String call_dateProcess(long d) {
		String formatStr = "yyyyMMdd-HH:mm:ss";
		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		String currDate = format.format(new Date(d));
		return messagedateProcess(currDate);
	}

	/**
	 * 处理时间 秒、分钟、小时、天
	 * 
	 * @param date
	 *            消息时间
	 */
	public static String messagedateProcess(String date) {

		String formatStr = "yyyyMMdd-HH:mm:ss";

		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		Date sendDate = null;
		try {
			sendDate = format.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		// 当前时间
		Date curDate = new Date(System.currentTimeMillis());

		// 分钟间隔
		int minDiff = (int) ((curDate.getTime() - sendDate.getTime()) / 1000);
		String dateStr = "";

		switch ((int) ((curDate.getTime() - sendDate.getTime()) / 1000 / 3600 / 24)) {
		case 0:
			formatStr = "HH:mm";
			format.applyPattern(formatStr);
			dateStr = curDate.getDate() != sendDate.getDate() ? "昨天 " : format
					.format(sendDate);
			break;
		case 1:
			if (curDate.getDate() - sendDate.getDate() < 2) {

				dateStr = "昨天 ";
			} else if (curDate.getDate() - sendDate.getDate() < 3) {
				dateStr = "前天 ";
			} else {
				formatStr = "MM-dd";
				format.applyPattern(formatStr);
				dateStr = format.format(sendDate);
			}
			break;
		default:
			formatStr = "MM-dd";
			format.applyPattern(formatStr);
			dateStr = format.format(sendDate);
			break;
		}
		return dateStr;
	}

	public static String dateProcess(String date) {

		String formatStr = "yyyyMMdd-HH:mm:ss";
		String dateStr = "";
		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		Date sendDate = null;
		try {
			sendDate = format.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		formatStr = "yyyy-MM-dd HH:mm";
		format.applyPattern(formatStr);
		dateStr = format.format(sendDate);

		return dateStr;
	}

	/**
	 * 通话记录时间显示
	 * 
	 * @param date
	 * @return
	 */
	public static String calllogdateProcess(String date) {

		String formatStr = "yyyyMMdd-HH:mm:ss";

		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		String call_date = format.format(new Date(date));
		Date sendDate = null;
		try {
			sendDate = format.parse(call_date);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		// 当前时间
		Date curDate = new Date(System.currentTimeMillis());

		// 分钟间隔
		int minDiff = (int) ((curDate.getTime() - sendDate.getTime()) / 1000);
		String dateStr = "";

		switch ((int) ((curDate.getTime() - sendDate.getTime()) / 1000 / 3600 / 24)) {
		case 0:
			formatStr = "HH:mm";
			format.applyPattern(formatStr);
			dateStr = curDate.getDate() != sendDate.getDate() ? "昨天 " : format
					.format(sendDate);
			break;
		case 1:
			if (curDate.getDate() - sendDate.getDate() < 2) {

				dateStr = "昨天 ";
			} else if (curDate.getDate() - sendDate.getDate() < 3) {
				dateStr = "前天 ";
			} else {
				formatStr = "MM-dd";
				format.applyPattern(formatStr);
				dateStr = format.format(sendDate);
			}
			break;
		default:
			formatStr = "MM-dd";
			format.applyPattern(formatStr);
			dateStr = format.format(sendDate);
			break;
		}
		return dateStr;
	}

	// 判断是否为中文
	public static Boolean isChinese(String str) {
		Pattern p_str = Pattern.compile("[\\u4e00-\\u9fa5]+");
		Matcher m = p_str.matcher(str);
		if (m.find() && m.group(0).equals(str)) {
			return true;
		} else {
			return false;
		}
	}

	// 屏蔽特殊字符
	public static String stringFilter(String str) throws PatternSyntaxException {
		String regEx = "[/\\:*?<>|\"\n\t\']";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.replaceAll("");
	}

	public static String stringToUnicode(char chineseChar) {
		return Integer.toHexString(chineseChar).toUpperCase();
	}

	public static int charToInt(String ch) {
		if (ch.equals("A")) {
			return 1;
		} else if (ch.equals("B")) {
			return 2;
		} else if (ch.equals("C")) {
			return 3;
		} else if (ch.equals("D")) {
			return 4;
		} else if (ch.equals("E")) {
			return 5;
		} else if (ch.equals("F")) {
			return 6;
		} else if (ch.equals("G")) {
			return 7;
		} else if (ch.equals("H")) {
			return 8;
		} else if (ch.equals("I")) {
			return 9;
		} else if (ch.equals("J")) {
			return 10;
		} else if (ch.equals("K")) {
			return 11;
		} else if (ch.equals("L")) {
			return 12;
		} else if (ch.equals("M")) {
			return 13;
		} else if (ch.equals("N")) {
			return 14;
		} else if (ch.equals("O")) {
			return 15;
		} else if (ch.equals("P")) {
			return 16;
		} else if (ch.equals("Q")) {
			return 17;
		} else if (ch.equals("R")) {
			return 18;
		} else if (ch.equals("S")) {
			return 19;
		} else if (ch.equals("T")) {
			return 20;
		} else if (ch.equals("U")) {
			return 21;
		} else if (ch.equals("V")) {
			return 22;
		} else if (ch.equals("W")) {
			return 23;
		} else if (ch.equals("X")) {
			return 24;
		} else if (ch.equals("Y")) {
			return 25;
		} else if (ch.equals("Z")) {
			return 26;
		}
		return 1;
	}

	public static String intToChar(int position) {
		String myMhar = "A";
		switch (position) {
		case 1:
			myMhar = "A";
			break;
		case 2:
			myMhar = "B";
			break;
		case 3:
			myMhar = "C";
			break;
		case 4:
			myMhar = "D";
			break;
		case 5:
			myMhar = "E";
			break;
		case 6:
			myMhar = "F";
			break;
		case 7:
			myMhar = "G";
			break;
		case 8:
			myMhar = "H";
			break;
		case 9:
			myMhar = "I";
			break;
		case 10:
			myMhar = "J";
			break;
		case 11:
			myMhar = "K";
			break;
		case 12:
			myMhar = "L";
			break;
		case 13:
			myMhar = "M";
			break;
		case 14:
			myMhar = "N";
			break;
		case 15:
			myMhar = "O";
			break;
		case 16:
			myMhar = "P";
			break;
		case 17:
			myMhar = "Q";
			break;
		case 18:
			myMhar = "R";
			break;
		case 19:
			myMhar = "S";
			break;
		case 20:
			myMhar = "T";
			break;
		case 21:
			myMhar = "U";
			break;
		case 22:
			myMhar = "V";
			break;

		case 23:
			myMhar = "W";
			break;
		case 24:
			myMhar = "X";
			break;
		case 25:
			myMhar = "Y";
			break;
		case 26:
			myMhar = "Z";
			break;
		}
		return myMhar;
	}

	/**
	 * 获取字符串最后一个汉字 null 说明不是汉字
	 * 
	 * @param str
	 * @return
	 */
	public static String getLastChar(String str) {
		String lastchar = null;
		if (str == null || "".equals(str)) {
			return null;
		}
		char c = str.charAt(str.length() - 1);
		if (isChinese(c)) {
			lastchar = String.valueOf(c);
		}
		return lastchar;

	}

	public static boolean isChinese(char c) {
		int v = (int) c;
		return (v >= 19968 && v <= 171941);

	}

	/**
	 * 获取汉字串拼音，英文字符不变
	 * 
	 * @param chinese
	 *            汉字串
	 * @return 汉语拼音全拼
	 */
	public static String getFullSpell(String chinese) {
		StringBuffer pybf = new StringBuffer();
		char[] arr = chinese.toCharArray();
		HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
		defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
		defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] > 128) {
				try {
					// 判断是否中文
					if (arr[i] >= 0x4e00 && arr[i] <= 0x9fa5) {
						pybf.append(PinyinHelper.toHanyuPinyinStringArray(
								arr[i], defaultFormat)[0]);
					} else {
						pybf.append(arr[i]);
					}
				} catch (BadHanyuPinyinOutputFormatCombination e) {
					e.printStackTrace();
				}
			} else {
				pybf.append(arr[i]);
			}
		}
		return pybf.toString().toLowerCase();
	}

	/**
	 * 汉语拼音转换工具
	 * 
	 * @param chinese
	 * @return 首拼
	 */
	public static String converterToPinYin(String chinese) {
		String pinyinString = "";
		char[] charArray = chinese.toCharArray();
		// 根据需要定制输出格式，我用默认的即可
		HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
		try {
			// 遍历数组，ASC码大于128进行转换
			for (int i = 0; i < charArray.length; i++) {
				if (charArray[i] > 128) {
					// charAt(0)取出首字母
					if (charArray[i] >= 0x4e00 && charArray[i] <= 0x9fa5) { // 判断是否中文
						pinyinString += PinyinHelper.toHanyuPinyinStringArray(
								charArray[i], defaultFormat)[0].charAt(0);
					} else { // 不是中文的打上未知，所以无法处理韩文日本等等其他文字
						pinyinString += "?";
					}
				} else {
					pinyinString += charArray[i];
				}
			}
			return pinyinString;
		} catch (BadHanyuPinyinOutputFormatCombination e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 把单个英文字母或者字符串转换成数字ASCII码
	 * 
	 * @param input
	 * @return
	 */
	public static int character2ASCII(String input) {
		char[] temp = input.toCharArray();
		StringBuilder builder = new StringBuilder();
		for (char each : temp) {
			builder.append((int) each);
		}
		String result = builder.toString();
		return Integer.parseInt(result);
	}

	/**
	 * 判断数字
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isNumeric(String str) {
		Pattern pattern = Pattern.compile("^[0-9]*$");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		} else {
			return true;
		}
	}

	/**
	 * 判读字母
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isLetter(String str) {
		Pattern pattern = Pattern.compile("^[A-Za-z]+$");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		} else {
			return true;
		}
	}

	/**
	 * 判断字母数字混合
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isAllLetter(String str) {
		Pattern pattern = Pattern.compile("^[A-Za-z0-9]+$");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		} else {
			return true;
		}
	}

	/**
	 * 去除开始为+86手机号码，修改为11为号码
	 * 
	 * @param mobiles
	 * @return
	 */
	public static boolean isMobileNO(String mobiles) {
		Pattern p = Pattern
				.compile("^((\\+86)|(86))?((13[0-9])|(15[^4,\\D])|(18[0,2-9])|(14[0-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}

	public static final String PATTERN_MOBILE_PHONE = "(^(\\d{3,4}-)?\\d{7,8})$|(^((13[0-9])|(15[0-9])|(18[0-9]))\\d{8})$";

	/**
	 * 验证合法手机号码
	 * 
	 * @param number
	 *            输入手机号码
	 * @return
	 */
	public static boolean isValidMobilePhoneNumber(String number) {
		if (isNullOrEmpty(number)) {
			return false;
		}

		return number.matches(PATTERN_MOBILE_PHONE);
	}

	public static String getOkNumber(String number) {
		String phoneNumber = "";
		if (number.length() > 11) {
			phoneNumber = number.substring(number.length() - 11,
					number.length());

		}

		return phoneNumber;

	}

	/***
	 * 获取配置文件的值
	 * 
	 * @param context
	 * @param key
	 * @return
	 * @throws Exception
	 */
	public static String getMetaValue(Context context, String key)
			throws Exception {
		PackageManager pm = context.getPackageManager();
		ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(),
				PackageManager.GET_META_DATA);
		Bundle bundle = ai.metaData;
		return bundle.getString(key);
	}

	/**
	 * 获取手机mac地址
	 * 
	 * @param context
	 * @return
	 */
	public static String getMacAddress(Context context) {
		String macAddress = "";
		WifiManager wifiMgr = (WifiManager) context
				.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = (null == wifiMgr ? null : wifiMgr.getConnectionInfo());
		if (null != info) {
			macAddress = info.getMacAddress();
		}
		return macAddress;
	}

	/**
	 * 短信的接收时间显示
	 * 
	 * @param recTime
	 * @return
	 */
	public static String messageReceiveTime(long recTime) {
		String resultTime = "";
		String formatStr = "yyyyMMdd-HH:mm:ss";
		// 消息时间
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		Date sendDate = new Date(recTime);

		// 当前时间
		Date curDate = new Date(System.currentTimeMillis());

		// 分钟间隔
		int minDiff = (int) ((curDate.getTime() - sendDate.getTime()) / 1000);

		switch ((int) ((curDate.getTime() - sendDate.getTime()) / 1000 / 3600 / 24)) {
		case 0:

			// resultTime = curDate.getDate() != sendDate.getDate() ? "昨天 "
			// : format.format(sendDate);

			if (curDate.getDate() - sendDate.getDate() < 1) {
				formatStr = "HH:mm";
				format.applyPattern(formatStr);
				resultTime = format.format(sendDate);
			} else {
				formatStr = "MM-dd";
				format.applyPattern(formatStr);
				resultTime = format.format(sendDate);
			}
			break;
		case 1:
			/*
			 * if (curDate.getDate() - sendDate.getDate() < 2) {
			 * 
			 * resultTime = "昨天 "; } else if (curDate.getDate() -
			 * sendDate.getDate() < 3) { resultTime = "前天 "; } else { formatStr
			 * = "yyyy-MM-dd"; format.applyPattern(formatStr); resultTime =
			 * format.format(sendDate); }
			 */
			formatStr = "MM-dd";
			format.applyPattern(formatStr);
			resultTime = format.format(sendDate);
			break;
		default:
			formatStr = "MM-dd";
			format.applyPattern(formatStr);
			resultTime = format.format(sendDate);
			break;
		}

		return resultTime;
	}

	public static boolean hasSdcard() {
		String state = Environment.getExternalStorageState();
		if (state.equals(Environment.MEDIA_MOUNTED)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 图片圆角 FIXME
	 * 
	 * @param bitmap
	 * @param pixels
	 * @return
	 */
	public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
		Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
				bitmap.getHeight(), Config.ARGB_8888);
		Canvas canvas = new Canvas(output);
		final int color = 0xff424242;
		final Paint paint = new Paint();
		final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
		final RectF rectF = new RectF(rect);
		final float roundPx = pixels;
		paint.setAntiAlias(true);
		canvas.drawARGB(0, 0, 0, 0);
		paint.setColor(color);
		canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
		paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
		canvas.drawBitmap(bitmap, rect, rect, paint);
		return output;
	}

	/**
	 * 自定义ListView高度
	 * 
	 * @param listView
	 */
	public void setListViewHeightBasedOnChildren(ListView listView) {
		// 获取ListView对应的adapter
		ListAdapter adapter = listView.getAdapter();
		if (adapter != null) {
			return;
		}
		int totalHeight = 0;
		for (int i = 0, len = adapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
			View listItem = adapter.getView(i, null, listView);
			listItem.measure(0, 0); // 计算子项View 的宽高
			totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
			ViewGroup.LayoutParams params = listView.getLayoutParams();
			params.height = totalHeight
					+ (listView.getDividerHeight() * (adapter.getCount() - 1));
			// listView.getDividerHeight()获取子项间分隔符占用的高度
			// params.height最后得到整个ListView完整显示需要的高度
			listView.setLayoutParams(params);
		}
	}

	/**
	 * sdCard创建文件夹
	 * 
	 * @param filePath
	 * @param context
	 * @return
	 */
	public static String createSdcardFile(String filePath, Context context) {
		String path = null;
		if (Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState())) {
			// 创建一个文件夹对象，赋值为外部存储器的目录
			File sdcardDir = Environment.getExternalStorageDirectory();
			// 得到一个路径，内容是sdcard的文件夹路径和名字
			path = sdcardDir.getPath() + filePath;
			File file = new File(path);
			if (!file.exists()) {
				// 若不存在，创建目录，可以在应用启动的时候创建
				file.mkdirs();
			}
		} else {
			Toast.makeText(context, "sdCard不存在", Toast.LENGTH_SHORT).show();
		}
		return path;
	}

	/**
	 * 计算图片的缩放值
	 * 
	 * @param options
	 * @param reqWidth
	 * @param reqHeight
	 * @return
	 */
	public static int calculateInSampleSize(BitmapFactory.Options options,
			int reqWidth, int reqHeight) {
		final int height = options.outHeight;
		final int width = options.outWidth;
		int inSampleSize = 1;

		if (height > reqHeight || width > reqWidth) {
			final int heightRatio = Math.round((float) height
					/ (float) reqHeight);
			final int widthRatio = Math.round((float) width / (float) reqWidth);
			inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
		}
		return inSampleSize;
	}
	
	//计算图片原始大小
	public static int SampleSize(BitmapFactory.Options options,int minSideLength, int maxNumOfPixels){
		double w = options.outWidth;   
	    double h = options.outHeight;
	 // 上下限范围   
	    int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math   
	            .sqrt(w * h / maxNumOfPixels));   
	    int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(   
	            Math.floor(w / minSideLength), Math.floor(h / minSideLength));   
	  
	    if (upperBound < lowerBound) {   
	        // return the larger one when there is no overlapping zone.   
	        return lowerBound;   
	    }   
	  
	    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {   
	        return 1;   
	    } else if (minSideLength == -1) {   
	        return lowerBound;   
	    } else {   
	        return upperBound;   
	    }   

	}
	
	//根据原始图片大小进行缩放
	public static int computeSampleSize(BitmapFactory.Options options,   
	        int minSideLength, int maxNumOfPixels) {   
	    int initialSize = SampleSize(options, minSideLength,   
	            maxNumOfPixels);   
	  
	    int roundedSize;   
	    if (initialSize <= 8) {   
	        roundedSize = 1;   
	        while (roundedSize < initialSize) {   
	            roundedSize <<= 1;   
	        }   
	    } else {   
	        roundedSize = (initialSize + 7) / 8;   
	    }   
	  
	    return roundedSize;   
	}   

	/**
	 * 递归删除 文件/文件夹
	 * 
	 * @param file
	 */
	public static void deleteFile(File file) {
		if (file.exists()) {
			if (file.isFile()) {
				file.delete();
			} else if (file.isDirectory()) {
				File files[] = file.listFiles();
				for (int i = 0; i < files.length; i++) {
					deleteFile(files[i]);
				}
			}
			file.delete();
		} 
	}


//	/**
//	 * 根据路径获得图片并压缩，返回bitmap用于显示
//	 * 
//	 * @param filePath
//	 * @return
//	 */
//	@SuppressLint("SdCardPath")
//	public static String getsmallBitmap(String filePath,int i){
//		if(filePath==null||filePath.length()==0)
//			return null;
//		
//		    FileDescriptor fd;
//			try {
//				fd = new FileInputStream(filePath).getFD();
//			 
//	        BitmapFactory.Options options = new BitmapFactory.Options();   
//	        options.inJustDecodeBounds = true;   
//	        // BitmapFactory.decodeFile(imgFile, options);   
//	        BitmapFactory.decodeFileDescriptor(fd, null, options);   
//	        
////	        FileInputStream fis = new FileInputStream(filePath);
////	        BitmapFactory.decodeStream(fis);
//	        options.inSampleSize = computeSampleSize(options, -1,1080*720);   
//	        try {   
//	            // 这里一定要将其设置回false，因为之前我们将其设置成了true   
//	            // 设置inJustDecodeBounds为true后，decodeFile并不分配空间，即，BitmapFactory解码出来的Bitmap为Null,但可计算出原始图片的长度和宽度   
//	            options.inJustDecodeBounds = false;   	  
//	            Bitmap bmp = BitmapFactory.decodeFile(filePath, options); 
//	           
//	            bmp = BitmapCache.loadBitmap(filePath,bmp);
//	            
//	            FileOutputStream fos = null;
//	    		String tempTaskPath = "/sdcard/ManagerAssistant/TaskPic/";
//	    		String I = i+"";
//	    		String name = DateFormat.format("yyyyMMdd_hhmmss",
//	    				Calendar.getInstance(Locale.CHINA))
//	    				+I+ ".jpg";
//	    		try {
//	    			File file = new File(tempTaskPath);
//	    			file.mkdirs();// 创建文件夹
//	    			String fileName = "/sdcard/ManagerAssistant/TaskPic/" + name;
//	    			fos = new FileOutputStream(fileName);
//	    			bmp.compress(Bitmap.CompressFormat.JPEG, 40, fos);
//	    			fos.flush();
//	    			fos.close();
//	    			if (!bmp.isRecycled()) {
//	    				bmp.recycle();
//	    			}
//	    			return fileName;
//	    			//return file.getAbsolutePath();
//	    		} catch (IOException e) {
//	    			e.printStackTrace();
//	    		}
//	    		if (!bmp.isRecycled()) {
//	    			bmp.recycle();
//	    		}
//	    		return null;
//	        } catch (OutOfMemoryError err) {   
//	            return null;   
//	        }   
//			} catch (FileNotFoundException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//				return null;  
//			} catch (IOException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//				return null;  
//			}  
//
//	}
	@SuppressLint("SdCardPath")
	public static String getSmallBitmap(String filePath) {
		
		if(filePath==null||filePath.length()==0)
			return null;
		
		final BitmapFactory.Options options = new BitmapFactory.Options();
		options.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(filePath, options);
		// Calculate inSampleSize
//		options.inSampleSize = calculateInSampleSize(options, 1080, 720);
		// Decode bitmap with inSampleSize set
		options.inSampleSize = computeSampleSize(options,  -1,1080*720);   

		options.inJustDecodeBounds = false;
		Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
		FileOutputStream fos = null;
		String tempTaskPath = "/sdcard/ManagerAssistant/TaskPic/";
		String name = DateFormat.format("yyyyMMdd_hhmmss",
				Calendar.getInstance(Locale.CHINA))
				+ ".jpg";
		try {
			File file = new File("tempTaskPath");
			file.mkdirs();// 创建文件夹
			String fileName = "/sdcard/ManagerAssistant/TaskPic/" + name;
			fos = new FileOutputStream(fileName);
			bmp.compress(Bitmap.CompressFormat.JPEG, 40, fos);
			fos.flush();
			fos.close();
			if (!bmp.isRecycled()) {
				bmp.recycle();
			}
			return fileName;
			//return file.getAbsolutePath();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (!bmp.isRecycled()) {
			bmp.recycle();
		}
		return null;
	}

	/**
	 * 多个文件压缩成一个zip
	 * 
	 * @param srcfile源文件列表
	 * 
	 * @param zipfile压缩后的文件
	 */
	public static void zipFiles(List<String> srcfile, File zipfile) {
		byte[] buf = new byte[1024];
		try {
			// ZipOutputStream类：完成文件或文件夹的压缩
			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
					zipfile));
			for (int i = 0; i < srcfile.size(); i++) {
				FileInputStream in = new FileInputStream(new File(
						srcfile.get(i)));
				out.putNextEntry(new ZipEntry(new File(srcfile.get(i))
						.getName()));
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
				out.closeEntry();
				in.close();
			}
			out.close();
			System.out.println("压缩完成.");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * dialog显示
	 * 
	 * @param context
	 * @param message
	 */
	public static boolean showDialog(Context context, String message) {

		return false;

	}

	/**
	 * 改变关键字颜色
	 * @param context
	 * @param keyWord
	 * @param strForChange
	 * @param keyColor
	 * @param otherColor
	 * @return 参数不对就返回null；
	 */
	public static SpannableStringBuilder changeColor(Context context,
			String keyWord, String strForChange, int keyColor, int otherColor) {
		
		if(context==null || keyWord==null || strForChange==null) return null;
		
		SpannableStringBuilder builder = new SpannableStringBuilder(strForChange);
		ForegroundColorSpan keySpan =null;
		ForegroundColorSpan otherSpan=null;
		
		try {
			keySpan= new ForegroundColorSpan(context
					.getResources().getColor(keyColor));
			otherSpan= new ForegroundColorSpan(context
					.getResources().getColor(otherColor));
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
		if (StringUtil.isEmpty(keyWord) || !strForChange.contains(keyWord)
				|| keyWord.length() > strForChange.length()) {
			return builder;
		}
		
		int keyLen = keyWord.length();
		// 如果是在开始和结尾
		if (strForChange.startsWith(keyWord)) {
			builder.setSpan(keySpan, 0, keyLen,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(otherSpan, keyLen, strForChange.length(),
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

		} else if (strForChange.endsWith(keyWord)) {
			builder.setSpan(keySpan, strForChange.length() - keyLen, strForChange.length(),
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(otherSpan, 0, strForChange.length() - keyLen,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

		} else {
			// 如果在中间
			int keyWorkPosition = 0;
			for (int i = 0; i < strForChange.length() - keyLen; i++) {
				if (keyWord.equals(strForChange.substring(i, i + keyLen))) {
					keyWorkPosition = i;
				}
			}
			builder.setSpan(otherSpan, 0, keyWorkPosition,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			builder.setSpan(keySpan, keyWorkPosition, keyWorkPosition + keyLen,
					Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			builder.setSpan(otherSpan, keyWorkPosition + keyLen, strForChange.length(),
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

		}
		return builder;
	}

	

	/**
	 * 设置begin到end中间的字体颜色,然后textView.setText(style)
	 * 
	 * @author lvbo
	 * @param text
	 * @param begin
	 * @param end
	 * @return
	 * @version 创建时间：2014-5-28 上午11:27:28
	 */
	public static SpannableStringBuilder spannableString(String text,
			int begin, int end, int color) {
		SpannableStringBuilder style = new SpannableStringBuilder(text);

		style.setSpan(new ForegroundColorSpan(color), begin, end,
				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);// 设置begin到end中间的字体颜色
		return style;
	}

	/**
	 * 通过指定的电话号码查询本地联系人姓名 11位数字
	 * 注意：现已将联系人放在自己创建的数据库
	 * @param context
	 * @param phoneNum
	 * @return
	 */
	@Deprecated
	public static String getContactNameFromPhoneBook(Context context,
			String phoneNum) {
		String contactName = "";
		ContentResolver cr = context.getContentResolver();
		Cursor pCur = cr.query(
				ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
				ContactsContract.CommonDataKinds.Phone.NUMBER + " = ?",
				new String[] { phoneNum }, null);
		if (pCur.moveToFirst()) {
			contactName = pCur
					.getString(pCur
							.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
			pCur.close();
		}
		return contactName;
	}


	/**
	 * 根据电话号码获取本地联系人姓名
	 * 注意：现已将联系人放在自己创建的数据库
	 * @张锋
	 * @param context
	 * @param phoneNum
	 * @return
	 */
	@Deprecated
	public static String getLocaContactsName(Context context, String phoneNum) {
		phoneNum=phoneNum.replace(" ", "").replace("+86", "").replace("-", "");
		String contactName = "";
		String number="";
		String[] projection = { ContactsContract.PhoneLookup.DISPLAY_NAME,   
                ContactsContract.CommonDataKinds.Phone.NUMBER};   
		ContentResolver cr = context.getContentResolver();
		Cursor pCur = cr.query(   
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,   
                projection,    // Which columns to return.   
                null, // WHERE clause.   
                null,          // WHERE clause value substitution   
                null);   // Sort order.  
		while (pCur.moveToNext()) {
			number = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
			number=number.replace(" ", "").replace("+86", "").replace("-", "");
			if(phoneNum.equals(number)){
				contactName= pCur.getString(pCur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
				break;
			}
		}

		if(pCur!=null)	pCur.close();
		if (contactName == "") {
			contactName = phoneNum;
		}
		return contactName;
	}



}
